package com.newear.bean;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by josan on 2018/6/6
 */

public class HistoryRecordInfo {
    public int curr;
    public int pageSize;
    public int pages;
    public List<ReportInfo> reportInfos;

    public boolean parse(JSONObject info) {
        if (info == null) {
            return false;
        }
        curr = info.optInt("curr");
        pageSize = info.optInt("page_size");
        pages = info.optInt("pages");

        if (info.has("reports")) {
            reportInfos = new ArrayList<>();
            JSONArray jsonArray = info.optJSONArray("reports");
            if (jsonArray != null) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    ReportInfo reportInfo = new ReportInfo();
                    if (reportInfo.parse(jsonArray.getJSONObject(i))) {
                        reportInfos.add(reportInfo);
                    }
                }
            }
        }
        return true;
    }
}
